import { ElNotification } from 'element-plus'
/*
  @eg const { $deep_clone } = getCurrentInstance()!.appContext.config!.globalProperties!
*/
export const globalMethods = {
    // 通用复制文字方法
    copy_text: (value: string, title: string = '') => {
        if (window.isSecureContext) {
            navigator.clipboard.writeText(value).then(() => {
                ElNotification({
                    type: 'success',
                    title: 'success',
                    message: `复制${title}成功！`,
                    duration: 1000,
                })
            })
        } else {
            const textArea = document.createElement('textarea')
            document.body.appendChild(textArea)
            textArea.textContent = value
            textArea.select()
            document.execCommand && document.execCommand('copy')
            textArea.remove()
            ElNotification({
                type: 'success',
                title: 'success',
                message: `复制${title}成功！`,
                duration: 1000,
            })
        }
    },
    // 深拷贝
    deep_clone: (target: any) => {
        const result = JSON.parse(JSON.stringify(target))
        return result
    },
}
